﻿/*-----------------------------------------------------------------------
 * <copyright file="WCFUnitCorrelation.svc.cs" company="O-RID">
 *     Copyright (c)2010 O-RID Co.,Ltd.
 * </copyright>
 * <author>Zhang Jun</author>
 * <summary>
 *          所有与UNIT操作相关的所有服务
 *          StatisticsToolsDB_new 数据库
 *
 *          作成日：07/13/2010
 *          
 *                  06/09/2011 增加 UNIT别日别查询、UNIT别期间别查询 追加案件名，线路选项
 * </summary>
 *-----------------------------------------------------------------------
 */
namespace Orid.Management.Statistics.Service.OPUnitService.UnitCorrelation
{
    using System;
    using System.Collections.Generic;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    using Orid.Management.Statistics.Service.OPUnitService.UnitCorrelation.ServiceModel;

    /// <summary>
    ///注意: 如果更改此处的类名 "WCFUnitCorrelation"，也必须更新 Web.config 中对 "WCFUnitCorrelation" 的引用。
    /// </summary>
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class WCFUnitCorrelation : IWCFUnitCorrelation
    {
        #region   UNIT别 日别 查询
        /// <summary>
        /// 显示 所有组别日期别信息
        /// IWCFUnitEntrySpeedQuery服务
        /// IWCFUnitEntrySpeedQuery.xaml
        /// </summary>
        /// <param name="whereParametersList">where 条件列表</param>
        /// <returns>
        /// 返回 OPDurationEntrySpeedQueryInforData 的 LIST 形式
        /// </returns>
        public List<UnitEntrySpeedQueryInforData> SelectUnitEntrySpeedQueryInfor(List<WhereParameters> whereParametersList)
        {
            List<UnitEntrySpeedQueryInforData> unitEntrySpeedQueryInforDataList = null;
            try
            {

                #region 参数形式转换

                ////日期
                if (!whereParametersList[0].WhereentryDateFrom.Equals("null"))
                {
                    whereParametersList[0].WhereentryDateFrom = whereParametersList[0].WhereentryDateFrom.ToString().Trim();
                }

                if (!whereParametersList[0].WhereentryDateTo.Equals("null"))
                {
                    whereParametersList[0].WhereentryDateTo = whereParametersList[0].WhereentryDateTo.ToString().Trim();
                }

                ////jobclass
                if (String.IsNullOrEmpty(whereParametersList[0].WhereJobClass))
                {
                    whereParametersList[0].WhereJobClass = string.Empty;
                }
                else
                {
                    whereParametersList[0].WhereJobClass = whereParametersList[0].WhereJobClass.ToString().Trim();
                }

                ////ScriptType
                if (String.IsNullOrEmpty(whereParametersList[0].WhereScriptType))
                {
                    whereParametersList[0].WhereScriptType = string.Empty;
                }
                else
                {
                    whereParametersList[0].WhereScriptType = whereParametersList[0].WhereScriptType.ToString().Trim();
                }

                ////WordType
                if (String.IsNullOrEmpty(whereParametersList[0].WhereWordType))
                {
                    whereParametersList[0].WhereWordType = string.Empty;
                }
                else
                {
                    whereParametersList[0].WhereWordType = whereParametersList[0].WhereWordType.ToString().Trim();
                }

                ////是opid
                if (!string.IsNullOrEmpty(whereParametersList[0].WhereLoginName))
                {
                    whereParametersList[0].WhereLoginName = whereParametersList[0].WhereLoginName.Trim();
                }
                else
                {
                    whereParametersList[0].WhereLoginName = DBNull.Value.ToString();
                }

                ////是UNIT
                if (!string.IsNullOrEmpty(whereParametersList[0].WhereUnit))
                {
                    whereParametersList[0].WhereUnit = whereParametersList[0].WhereUnit.Trim();
                }
                else
                {
                    whereParametersList[0].WhereUnit = DBNull.Value.ToString();
                }

                ////案件名 
                if (!string.IsNullOrEmpty(whereParametersList[0].WhereMatterName))
                {
                    whereParametersList[0].WhereMatterName = whereParametersList[0].WhereMatterName.Trim();
                }
                else
                {
                    whereParametersList[0].WhereMatterName = DBNull.Value.ToString();
                }

                ////线路
                if (!string.IsNullOrEmpty(whereParametersList[0].WhereServer))
                {
                    whereParametersList[0].WhereServer = whereParametersList[0].WhereServer.Trim();
                }
                else
                {
                    whereParametersList[0].WhereServer = DBNull.Value.ToString();
                }

                #endregion

                unitEntrySpeedQueryInforDataList = DataProvider.GetSelectUnitEntrySpeedQueryInfor(whereParametersList);
            }
            catch (Exception ex)
            {
                Log4Service.Log log = new Orid.Management.Statistics.Service.Log4Service.Log();
                log.Error("WCFUnitEntrySpeedQuery SelectUnitEntrySpeedQueryInfor Error:" + ex.Message);
            }

            return unitEntrySpeedQueryInforDataList;

        }

        #endregion   UNIT别 日别 查询

        #region UNIT别 期间别 查询
        /// <summary>
        /// 显示 所有组别日期别信息
        /// IWCFUnitEntrySpeedQuery服务
        /// IWCFUnitEntrySpeedQuery.xaml
        /// </summary>
        /// <param name="whereParametersList">where 条件列表</param>
        /// <returns>
        /// 返回 OPDurationEntrySpeedQueryInforData 的 LIST 形式
        /// </returns>
        public List<UnitDurationEntrySpeedQueryInforData> SelectUnitDurationEntrySpeedQueryInfor(List<WhereParameters> whereParametersList)
        {
            List<UnitDurationEntrySpeedQueryInforData> unitDurationEntrySpeedQueryInforDataList = null;
            try
            {

                #region 参数形式转换

                ////日期
                if (!whereParametersList[0].WhereentryDateFrom.Equals("null"))
                {
                    whereParametersList[0].WhereentryDateFrom = whereParametersList[0].WhereentryDateFrom.ToString().Trim();
                }

                if (!whereParametersList[0].WhereentryDateTo.Equals("null"))
                {
                    whereParametersList[0].WhereentryDateTo = whereParametersList[0].WhereentryDateTo.ToString().Trim();
                }

                ////jobclass
                if (String.IsNullOrEmpty(whereParametersList[0].WhereJobClass))
                {
                    whereParametersList[0].WhereJobClass = string.Empty;
                }
                else
                {
                    whereParametersList[0].WhereJobClass = whereParametersList[0].WhereJobClass.ToString().Trim();
                }

                ////ScriptType
                if (String.IsNullOrEmpty(whereParametersList[0].WhereScriptType))
                {
                    whereParametersList[0].WhereScriptType = string.Empty;
                }
                else
                {
                    whereParametersList[0].WhereScriptType = whereParametersList[0].WhereScriptType.ToString().Trim();
                }

                ////WordType
                if (String.IsNullOrEmpty(whereParametersList[0].WhereWordType))
                {
                    whereParametersList[0].WhereWordType = string.Empty;
                }
                else
                {
                    whereParametersList[0].WhereWordType = whereParametersList[0].WhereWordType.ToString().Trim();
                }

                ////是opid
                if (!string.IsNullOrEmpty(whereParametersList[0].WhereLoginName))
                {
                    whereParametersList[0].WhereLoginName = whereParametersList[0].WhereLoginName.Trim();
                }
                else
                {
                    whereParametersList[0].WhereLoginName = DBNull.Value.ToString();
                }

                ////是UNIT
                if (!string.IsNullOrEmpty(whereParametersList[0].WhereUnit))
                {
                    whereParametersList[0].WhereUnit = whereParametersList[0].WhereUnit.Trim();
                }
                else
                {
                    whereParametersList[0].WhereUnit = DBNull.Value.ToString();
                }

                ////案件名 
                if (!string.IsNullOrEmpty(whereParametersList[0].WhereMatterName))
                {
                    whereParametersList[0].WhereMatterName = whereParametersList[0].WhereMatterName.Trim();
                }
                else
                {
                    whereParametersList[0].WhereMatterName = DBNull.Value.ToString();
                }

                ////线路
                if (!string.IsNullOrEmpty(whereParametersList[0].WhereServer))
                {
                    whereParametersList[0].WhereServer = whereParametersList[0].WhereServer.Trim();
                }
                else
                {
                    whereParametersList[0].WhereServer = DBNull.Value.ToString();
                }

                #endregion

                unitDurationEntrySpeedQueryInforDataList = DataProvider.GetSelectUnitDurationEntrySpeedQueryInfor(whereParametersList);
            }
            catch (Exception ex)
            {
                Log4Service.Log log = new Orid.Management.Statistics.Service.Log4Service.Log();
                log.Error("WCFUnitDurationEntrySpeedQuery SelectUnitDurationEntrySpeedQueryInfor Error:" + ex.Message);
            }

            return unitDurationEntrySpeedQueryInforDataList;

        }
        #endregion UNIT别 期间别 查询

        #region UNIT别 稼动率 查询
        /// <summary>
        /// UNIT别 稼动率 查询
        /// </summary>
        /// <param name="whereParametersList">where 的参数列表</param>
        /// <returns>返回 UnitWorkEfficDayQueryData 的LIST 形式</returns>
        public List<UnitWorkEfficQueryData> SelectUNITWorkEfficiencyInfor(List<WhereParameters> whereParametersList) 
        {
            try
            {
                List<UnitWorkEfficQueryData> retUnitWorkEfficiencyList = null;

                #region 参数形式转换

                ////日期
                if (!whereParametersList[0].WhereentryDateFrom.Equals("null"))
                {
                    whereParametersList[0].WhereentryDateFrom = whereParametersList[0].WhereentryDateFrom.ToString().Trim();
                }

                if (!whereParametersList[0].WhereentryDateTo.Equals("null"))
                {
                    whereParametersList[0].WhereentryDateTo = whereParametersList[0].WhereentryDateTo.ToString().Trim();
                }

                if (!string.IsNullOrEmpty(whereParametersList[0].WhereUnit))
                {
                    ////是UNIT
                    whereParametersList[0].WhereUnit = whereParametersList[0].WhereUnit.Trim();
                }
                else
                {
                    whereParametersList[0].WhereUnit = DBNull.Value.ToString();
                }

                #endregion 参数设置

                string procedureName = string.Empty;

                if (!string.IsNullOrEmpty(whereParametersList[0].WhereStatsticClass))
                {
                    switch (whereParametersList[0].WhereStatsticClass.ToString().Trim().ToUpper())
                    {
                        case "DAY":
                            retUnitWorkEfficiencyList = DataProvider.GetSelectUnitWorkEfficiencyDay(whereParametersList);
                            break;

                        case "HOUR":
                            retUnitWorkEfficiencyList = DataProvider.GetSelectUnitWorkEfficiencyHour(whereParametersList);
                            break;
                    }
                }

                return retUnitWorkEfficiencyList;
            }
            catch (Exception ex)
            {
                Log4Service.Log log = new Orid.Management.Statistics.Service.Log4Service.Log();
                log.Error("WCFUnitCorrelation SelectUNITWorkEfficiencyInfor Error:" + ex.Message);
            }

            return null;
        }
        #endregion UNIT别 稼动率 查询
    }
}
